﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;

namespace Coder.Framework
{

    /// <summary>
    /// Allows access to the web via standard HTTP methods.
    /// </summary>
    public class WebClient
    {
        HttpClient _httpClient;

        /// <summary>
        /// Creates the WebClient.
        /// </summary>
        public WebClient()
        {
            _httpClient = new HttpClient();
        }

        /// <summary>
        /// Retrieves web content.
        /// </summary>
        /// <param name="url">Represents the URL in string format.</param>
        /// <returns>Returns a string with the web content.</returns>
        public async Task<string> RetrieveDocURL(string url)
        {

            string doc = await _httpClient.GetStringAsync(url);

            return doc;
        }

        /// <summary>
        /// Retrieves web content.
        /// </summary>
        /// <param name="uri">Represents the URL in URI format</param>
        /// <returns>Returns a string with the web content.</returns>
        public async Task<string> RetrieveDocURL(Uri uri)
        {
            string doc = await _httpClient.GetStringAsync(uri);

            return doc;
        }

        /// <summary>
        /// Retrieves an image in byte[] format.
        /// </summary>
        /// <param name="url">Represents the URL in string format.</param>
        /// <returns>Returns a byte array containing pixel formatting.</returns>
        public async Task<byte[]> RetrieveImageURL(string url)
        {
            return await _httpClient.GetByteArrayAsync(url);
        }
    }
}
